home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.12 Dec 94 / QC sample code < prev   
Encoding:
Text File  |  1994-10-20  |  2.1 KB  |  80 lines  |  [TEXT/R*ch]

  1. Listing 1: QCTools.c
  2.  
  3. #include “QCAPI.h”
  4.  
  5. // turn on QC for testing
  6. void StartQCTesting(void)
  7. {
  8.     if (QCInstalled())
  9.         if (!QCIsActive())
  10.             QCActivate(NULL);
  11. }
  12.  
  13. // turn off QC when we’re done
  14. voidStopQCTesting(void)
  15. {
  16.     if (QCInstalled())
  17.         if (QCIsActive())
  18.             QCDeactivate(NULL);
  19. }
  20.  
  21. // Turn on arbitrary set of tests depending on build type; we
  22. // developed these test settings by guess and by gosh. You
  23. // can define similar functions for other levels of testing.
  24. void SetDevelopmentTests (void)
  25. {
  26.     QCErr testErr = noErr;
  27.     testErr = QCSetTestState(qcValidateHandlePointers, TRUE);
  28.     testErr = QCSetTestState(qcDetectWriteToZero, TRUE);
  29.     testErr = QCSetTestState(qcDerefZeroCheck, TRUE);
  30.     testErr = QCSetTestState(qcCheckDisposeRelease, TRUE);
  31.  
  32.     // make sure we see Macsbug error messages
  33.     testErr = QCSetTestState(qcDebugBreaks, TRUE);
  34. }
  35.  
  36. Listing 2: QCCallback.c
  37.  
  38. QC callbacks
  39. Sample callback which logs the error to a file instead of dropping into the debugger.
  40. This particular routine logs errors using the string that QC passes.
  41.  
  42. #include “QCAPI.h”
  43.  
  44. // the callback routine is defined as “typedef long (*QCCallBack)(QCPBPtr)”; 
  45. // the QCParamPtr tells us what type of test generated the error and what
  46. // error occured.
  47. long ErrorToFileCallback(QCPBPtr *theParam)
  48. {
  49.     QCErr anErr = kQCNoErr;
  50.     StringPtr s = NULL;
  51.  
  52.     // get the error message that would normally go to Macsbug
  53.     anErr = QCGetErrorText(theParam->errorID, s);
  54.     if (anErr == kQCNoErr)    
  55.     {
  56.             // log the message to our app log file
  57.             LogEventMessage(kErrorEvt, s);
  58.     }
  59.     else
  60.             LogEventMessage(kErrorEvent, ‘QC internal error’);
  61. }
  62.  
  63. // call this routine to make QC start using the callback.
  64. // In its original form, this routine gets called right before
  65. // the start of the main event loop. The second parameter
  66. // to QCInstallHandler is a refcon, so you can pass data to the handler
  67. // routine when it gets called.
  68. QCErr MyInstallQCCallBack (void)
  69. {
  70.     return QCInstallHandler(ErrorToFileCallBack, OL);
  71. }
  72.  
  73. // call this routine to make QC stop using the callback.
  74. // In its original form, this routine gets called right before
  75. // ExitToShell()
  76. QCErr MyUnInstallQCCallBack (void)
  77. {
  78.     return QCRemoveHandler();
  79. }
  80.